<?php

include_once ('operacionesBD.php');

function create_users_table($databaseOperator){
    $query = 'CREATE TABLE users (userid int auto_increment primary key,
        username varchar(50) NOT NULL, password varchar(1000) NOT NULL, mail
        varchar(50) NOT NULL)';
    $databaseOperator->modificar($query);
}

function create_playlists_table($databaseOperator){
    $query = 'CREATE TABLE playlists
        (playlistid int auto_increment primary key,
        name varchar(50) NOT NULL,
        xml varchar(1000) NOT NULL, 
        userid int NOT NULL, foreign key(userid)
        references users(userid))';
    $databaseOperator->modificar($query);
}

function create_metadata_table($databaseOperator){
    $query = 'CREATE TABLE metadata
        (metadataid int auto_increment primary key,
        artist varchar(50) NOT NULL,
        title varchar(50) NOT NULL, 
        track int NOT NULL, 
        year int NOT NULL,
        album varchar(50) NOT NULL,
        file varchar(50) NOT NULL,
        image varchar(50) NOT NULL,
        public boolean NOT NULL,
        userid int NOT NULL,
        foreign key(userid) references users(userid))';
    $databaseOperator->modificar($query);

}

function insert_admin_user($databaseOperator) {
    $query = "INSERT INTO users VALUES (NULL, 'admin', 'admin', 'admin@gmail.com')";
    $databaseOperator->modificar($query);   
}


$databaseOperator = operacionesBD::getInstance('localhost', 'root','', 'musica');

create_users_table($databaseOperator);
create_playlists_table($databaseOperator);
create_metadata_table($databaseOperator);
insert_admin_user($databaseOperator);

echo 'Done!';
    
?>
